package com.javasm.adminapi.module.activity.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.javasm.adminapi.common.RedisKeys;
import com.javasm.adminapi.module.activity.dao.AmActivityDao;
import com.javasm.adminapi.module.activity.entity.AmActivity;
import com.javasm.adminapi.module.activity.service.AmActivityService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * 活动管理-促销活动申请(AmActivity)表服务实现类
 *
 * @author makejava
 * @since 2025-10-15 14:40:03
 */
@Service("amActivityService")
@Transactional
public class AmActivityServiceImpl extends ServiceImpl<AmActivityDao, AmActivity> implements AmActivityService {
    @Resource
    RedisTemplate<String,AmActivity> redisTemplate;


    @Override
    public void removeRedisActivity(AmActivity... activities) {

        List<String> keyList = new ArrayList<>();
        for (AmActivity amActivity : activities){
            String uidkey = String.format(RedisKeys.AmActivity_Id,amActivity.getId());
            String activitykey = String.format(RedisKeys.AdminUser_ActivityName,amActivity.getActivityName());
            keyList.addAll(List.of(uidkey,activitykey));
        }
        redisTemplate.delete(keyList);//一次性删除多个key


    }

    @Override
    public Long checkRegActivity(AmActivity activity) {
        //判断活动名是否存在
        LambdaQueryWrapper<AmActivity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AmActivity::getActivityName, activity.getActivityName());
        //返回他的数量大小
        return count(queryWrapper);

    }

    @Override
    public void updateStatus(List<Integer> ids, Integer status) {

    }
}

